package ylsb.controller;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import ylsb.service.YltpyinjinService;
import ylsb.support.JsonResult;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("yinjin")
public class YltpYinjinController {
    @Resource
    YltpyinjinService ddService;

    public Logger log = LoggerFactory.getLogger(YltpBaofeiController.class);

    @RequestMapping("findyinjinlist")
    public JsonResult<?> findYinjinlist(@RequestParam("xiangmuid") String ppxiangmuId){
        try {
            return JsonResult.getSuccessResult(ddService.findyinjinlist(ppxiangmuId));

        }catch (Exception e) {
            e.printStackTrace();
            log.error("yinjin/findYiinjinlist:error",e);
            return JsonResult.getErrorResult("yinjin/findYinjinlist:error " + e.getMessage());
        }

    }

    @RequestMapping("findBiaojuelist")
    public JsonResult<?> findBiaojuelist(@RequestParam("xiangmuid") String ppxiangmuId,
                                         @RequestParam("userid") String ppuserId){
        try {
            List<Map<String, Object>> mmList=ddService.findBiaojuelist(ppxiangmuId,ppuserId);
            return JsonResult.getSuccessResult(mmList);
        }catch (Exception e) {
            e.printStackTrace();
            log.error("yinjin/findBiaojuelist:error",e);
            return JsonResult.getErrorResult("yinjin/findBiaojuelist:error " + e.getMessage());
        }
    }

    @RequestMapping("delete")
    public JsonResult<?> delete(@RequestParam("xiangmuid") String ppxiangmuId){
        try {

            return ddService.deleteByxiangmuId(ppxiangmuId)==true? JsonResult.getSuccessResult("删除材料成功")
                    : JsonResult.getErrorResult("删除材料失败");

        }catch (Exception e) {
            e.printStackTrace();
            log.error("yinjin/delete:error",e);
            return JsonResult.getErrorResult("yinjin/delete:error " + e.getMessage());
        }
    }


}
